package com.masterclient.app.modules.shop;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.eoner.baselib.widget.navgation.FCNavigationAction;
import com.eoner.baselib.widget.navgation.FCNavigationBar;
import com.eoner.baselibrary.widget.EnhanceTabLayout;
import com.eoner.middlelib.router.map.FCRouterPath;
import com.masterclient.app.R;
import com.masterclient.app.base.FCBusinessActivity;
import com.masterclient.app.modules.coupon.adapter.CouponPagerAdapter;
import com.masterclient.app.utils.CommonUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

@Route(path = FCRouterPath.STOCK_SET_PATH)
public class StockSetActivity extends FCBusinessActivity {

    @BindView(R.id.tabLayout)
    EnhanceTabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    @Autowired(name = "productId")
    String productId;

    private String explainUrl = "";

    @Override
    protected int requireGetLayoutId() {
        return R.layout.activity_stock_set;
    }

    @Override
    protected void requireSetCustomNavigationBar(FCNavigationBar navigationBar) {
        navigationBar.setTitle("库存设置").setLineHidden(true);
        navigationBar.setRightBtnText("库存说明");
        navigationBar.setGzgNavigationListener(action -> {
            if (action == FCNavigationAction.NAV_RIGHT_CLICK){
                CommonUtil.goAnyWhere(this,explainUrl,"","","","");
            }else if (action == FCNavigationAction.NAV_LEFT_CLICK){
                finish();
            }
        });
        navigationBar.setRightBtnTextColor(Color.parseColor("#525866"));
        navigationBar.setRightBtnTextSize(13);
    }

    @Override
    protected void requireInitUIAndData(Bundle savedInstanceState) {
        List<Fragment> list = new ArrayList<>();
        StockDetailsFragment stockDetailsFragment = StockDetailsFragment.getInstance(productId);
        stockDetailsFragment.setCallBackListener(url -> {
            explainUrl = url;
        });
        list.add(stockDetailsFragment);
        StockChangeFragment fragment2 = StockChangeFragment.getInstance(productId);
        list.add(fragment2);
        String [] sTitle = {"库存管理","库存变更"};
        CouponPagerAdapter pagerAdapter = new CouponPagerAdapter(getSupportFragmentManager(), list, sTitle);
        for(int i=0;i<sTitle.length;i++){
            tabLayout.addTab(sTitle[i],i == 0);
        }
        viewPager.setAdapter(pagerAdapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout.getTabLayout()));
        tabLayout.setupWithViewPager(viewPager);
    }
}
